#include <buola/scene/geodes/cplane.h>
#include <buola/scene/cmesh.h>
#include <buola/scene/cvertexdata.h>
#include <buola/scene/cindexdata.h>
#include <buola/scene/cmeshbuilder.h>
#include <BulletCollision/CollisionShapes/btStaticPlaneShape.h>

namespace buola { namespace scene {

static PMesh plane_mesh()
{
    std::vector<mat::CVec3d> lPositions;

    double lSize=10.0;
    
    lPositions.push_back({-lSize,-lSize,0});
    lPositions.push_back({ lSize,-lSize,0});
    lPositions.push_back({-lSize, lSize,0});
    lPositions.push_back({ lSize, lSize,0});

    std::vector<mat::CVec3d> lNormals;

    lNormals.push_back({ 0.0, 0.0, 1.0});

    std::vector<int> lVPos,lVNorm;

    lVPos.emplace_back(0);
    lVNorm.emplace_back(0);
    lVPos.emplace_back(1);
    lVNorm.emplace_back(0);
    lVPos.emplace_back(2);
    lVNorm.emplace_back(0);
    lVPos.emplace_back(3);
    lVNorm.emplace_back(0);

    std::vector<int> lFaces;
    lFaces.push_back(0);
    lFaces.push_back(4);

    std::vector<int> lSubMesh;
    lSubMesh.push_back(0);

    CMeshBuilder lBuilder;

    lBuilder.SetPosition(lPositions);
    lBuilder.SetNormal(lNormals);

    lBuilder.SetVertices(lVPos,lVNorm);

    lBuilder.SetFaces(lFaces);

    lBuilder.AddSubMesh("plane",lSubMesh,EPrimitive::TRIANGLE_STRIP);

    return lBuilder.BuildMesh();
}

CPlane::CPlane()
    :   CGeode(plane_mesh())
{
}

CPlane::~CPlane()
{
}

PBulletCollisionShape CPlane::GetCollisionShape()
{
    return PBulletCollisionShape(new btStaticPlaneShape(btVector3(0,0,1),0));
}

/*namespace gl*/ } /*namespace buola*/ }
